# -*- coding: utf-8 -*-
# @Time    : 2020/9/14 12:25
# @Author  : liuwenfan
# @File    : group_service.py
# @Software: PyCharm

from application import db
from application.models.mantis_models import MantisProjectTable, MantisProjectHierarchyTable


def get_group():
    # sql = "select a.id,a.name from mantis_project_table as a,mantis_project_hierarchy_table as b " \
    #       "where a.id = b.parent_id and a.enabled =1 " \
    #       "group by a.id"
    ret = db.session.query(MantisProjectTable.id, MantisProjectTable.name).join(MantisProjectHierarchyTable,
                                                                                MantisProjectTable.id == MantisProjectHierarchyTable.parent_id).filter(
        MantisProjectTable.enabled == 1).group_by(MantisProjectTable.id).all()
    # db.session.close()
    data = [{"group_id": i, "group_name": j} for i, j in ret]
    return data
